package com.smartthinking.destinomusical.ws;

import java.util.ArrayList;

import com.smartthinking.destinomusical.obj.SearchParams;
import com.smartthinking.destinomusical.parser.ParserCanciones;
import com.smartthinking.destinomusical.parser.ParserCategoria;
import com.smartthinking.destinomusical.parser.ParserCliente;
import com.smartthinking.destinomusical.parser.ParserInsert;
import com.smartthinking.destinomusical.parser.ParserPromocion;
import com.smartthinking.destinomusical.parser.ParserSuscripciones;

public class ConexionHTTP {
//	private static String URL = "http://www.smartthinking.com.mx:9080/DestinoMusical/DataServlet?%s";
//	private static String URL = "epura.k-box.com/DataServlet?%s";
	private static String URL = "http://epura.k-box.com/DataServlet?%s";

	

	public ArrayList consulta(SearchParams obj) {

		String url = String.format(URL, obj.getQuery());
		url.replaceAll(" ", "%20");
		System.out.println("URL: " + url);
		ArrayList array = xmlParseo(obj.getTipo(), url);
		return array;

	}

	private ArrayList xmlParseo(int parseo, String url) {
		ArrayList temp = new ArrayList();
		switch (parseo) {
		case 1:
			ParserCategoria xmlParser = new ParserCategoria(url);
			temp = xmlParser.parse();
			break;
		case 2:
			ParserSuscripciones xmlParser2 = new ParserSuscripciones(url);
			temp = xmlParser2.parse();
			break;

		case 3:
			ParserCanciones xmlParser3 = new ParserCanciones(url);
			temp = xmlParser3.parse();
			break;
		case 4:
			ParserInsert xmlParser4 = new ParserInsert(url);
			temp = xmlParser4.parse();
			break;
		case 5:
			ParserCanciones xmlParser5 = new ParserCanciones(url);
			temp = xmlParser5.parse();
			break;
		case 6:
			ParserCliente xmlParser6 = new ParserCliente(url);
			temp = xmlParser6.parse();
			break;
		case 7:
			ParserPromocion xmlParser7 = new ParserPromocion(url);
			temp = xmlParser7.parse();
			break;
		default:
			break;

		}
		return temp;

	}

}
